package com.crm.miaohe.controller.order;

import com.crm.miaohe.controller.order.request.OrderHistoryRequest;
import com.crm.miaohe.entity.order.statistics.DailyOrderSummary;
import com.crm.miaohe.entity.order.statistics.HistoryOrderSummary;
import com.crm.miaohe.service.OrderStatisticsService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@RequestMapping("/api/erp/order/statistics")
public class OrderStatisticsController {

    private final OrderStatisticsService orderStatisticsService;

    public OrderStatisticsController(OrderStatisticsService orderStatisticsService) {
        this.orderStatisticsService = orderStatisticsService;
    }

    @GetMapping("/daily")
    public ResponseEntity<DailyOrderSummary> dailyOrderSummary() {
        return ResponseEntity.ok(orderStatisticsService.getDailyStatistics());
    }

    @GetMapping("/history")
    public ResponseEntity<HistoryOrderSummary> historyOrderSummary(@Valid OrderHistoryRequest request) {
        return ResponseEntity.ok(orderStatisticsService.getHistorySummary(request.getStart(), request.getEnd()));
    }
}
